package com.googlecode.yoohoo.xmppcore.stream.features;

import com.googlecode.yoohoo.xmppcore.protocol.IFeature;
import com.googlecode.yoohoo.xmppcore.protocol.translation.IXmlWriter;
import com.googlecode.yoohoo.xmppcore.protocol.translation.XmlWriter;

public class StartTls implements IFeature {
	private boolean required;
	
	public StartTls() {
		this(true);
	}
	
	public StartTls(boolean required) {
		this.required = required;
	}
	
	public boolean isRequired() {
		return required;
	}
	
	public void setRequired(boolean required) {
		this.required = required;
	}
	
	@Override
	public String toXml() {
		IXmlWriter writer = new XmlWriter();
		writer.writeStartElement("starttls");
		writer.writeNamespace("urn:ietf:params:xml:ns:xmpp-tls");
		
		if (required) {
			writer.writeEmptyElement("required");
		}
		
		writer.writeEndElement();
		
		return writer.toXml();
	}

}
